*Shift-share robustness analysis following Adao et al. (2019). Table  D.17.
*before run do  "$path\clean_data_adao.do"

use "$temp/Long_shares.dta", clear
collapse share, by(ind39)
drop share
gen n=_n
save "$temp/industries.dta", replace

*primary all
use "$temp/bartik_50_c_sample.dta", clear

joinby mun39 using "$temp/wide_shares_sample.dta"

tab laani50, gen(laani_dum)

global controls town city agrishare_1940 manushare_1940 laani_dum*
local cpath "$temp/industries.dta"

reg_ss primary50_individual, shiftshare_var(bartik_standardized) control_varlist($controls) share_varlist(share_1-share_89)  weight_var(wei) alpha(0.05) akmtype(1)  path_cluster(`cpath') cluster_var(ind39)

display e(CI_low)
display  e(CI_upp)

*primary agri background

use "$temp/bartik_50_c_agri_sample.dta", clear

joinby mun39 using "$temp/wide_shares_sample_agri.dta"

tab laani50, gen(laani_dum)

local cpath "$temp/industries.dta"

reg_ss primary50_individual, shiftshare_var(bartik_standardized) control_varlist($controls) share_varlist(share_1-share_89)  weight_var(wei) alpha(0.05) akmtype(1) path_cluster(`cpath') cluster_var(ind39)

display e(CI_low)
display  e(CI_upp)

*Income all

use "$temp/bartik_70_c_sample.dta", clear

joinby mun39 using "$temp/wide_shares_sample_70.dta"

tab laani50, gen(laani_dum)
local cpath "$temp/industries.dta"

reg_ss ln_svatv, shiftshare_var(bartik_standardized) control_varlist($controls) share_varlist(share_1-share_89)  weight_var(wei) alpha(0.05) akmtype(1) path_cluster(`cpath') cluster_var(ind39)

display e(CI_low)
display  e(CI_upp)

*Income agri

use "$temp/bartik_70_c_agri_sample.dta", clear

joinby mun39 using "$temp/wide_shares_sample_agri_70.dta"

tab laani50, gen(laani_dum)
local cpath "$temp/industries.dta"
reg_ss ln_svatv, shiftshare_var(bartik_standardized) control_varlist($controls) share_varlist(share_1-share_89)  weight_var(wei) alpha(0.05) akmtype(1) path_cluster(`cpath') cluster_var(ind39)

display e(CI_low)
display  e(CI_upp)

*change in degrees and yos

use "$temp/bartik_young_sample.dta", clear

preserve 
use "$temp/bartik_young_old" ,clear
keep mun39 young hdegree yos 
reshape wide hdegree yos, i(mun39) j(young)
gen diff_yos=yos1-yos0
gen diff_hdegree=hdegree1-hdegree0
tempfile change
save `change'
restore 

joinby mun39 using  `change'

joinby mun39 using "$temp/wide_shares_sample_young.dta"

tab laani50, gen(laani_dum)

local cpath "$temp/industries.dta"
reg_ss diff_yos, shiftshare_var(bartik_standardized) control_varlist($controls) share_varlist(share_1-share_89)  weight_var(wei) alpha(0.05) akmtype(1) path_cluster(`cpath') cluster_var(ind39)

display e(CI_low)
display  e(CI_upp)

local cpath "$temp/industries.dta"
reg_ss diff_hdegree, shiftshare_var(bartik_standardized) control_varlist($controls) share_varlist(share_1-share_89)  weight_var(wei) alpha(0.05) akmtype(1) path_cluster(`cpath') cluster_var(ind39)

display e(CI_low)
display  e(CI_upp)

*Income rank UM

use "$temp/bartik_young_UM_sample.dta", clear

joinby mun39 using "$temp/wide_shares_sample_UM.dta"

tab laani50, gen(laani_dum)
local cpath "$temp/industries.dta"

reg_ss income_rank, shiftshare_var(bartik_standardized) control_varlist($controls) share_varlist(share_1-share_89)  weight_var(wei) alpha(0.05) akmtype(1) path_cluster(`cpath') cluster_var(ind39)

display e(CI_low)
display  e(CI_upp)

